
#include "ImageManager.hpp"

using namespace Gomoku::UI;

ImageManager::ImageManager()
{

}

ImageManager::~ImageManager()
{
	std::map<std::string, sf::Image*>::iterator ite = this->_sfImages.end();
	for (std::map<std::string, sf::Image*>::iterator it = this->_sfImages.begin(); it != ite; ++it)
		delete it->second;
}

sf::Image* ImageManager::getImage(std::string const & name)
{
	if (this->_sfImages.find(name) != this->_sfImages.end())
		return this->_sfImages[name];
	return 0;
}

sf::Sprite* ImageManager::getSprite(std::string const & name)
{
	sf::Image* image = this->getImage(name);
	if (image != 0)
		return new sf::Sprite(*image);
	return 0;
}

void ImageManager::_loadImage(std::string const & name, std::string const & path)
{
	sf::Image* image = new sf::Image();
	if (image->LoadFromFile(path))
		this->_sfImages[name] = image;
	else
		delete image;
}